package tmp;

import java.net.URL;

import HTTPClient.HTTPConnection;
import HTTPClient.HTTPResponse;
import HTTPClient.NVPair;

public class Cliente {
	private static HTTPConnection con;
	private static HTTPResponse rsp = null;
	private static String site = "http://www.cbs.dtu.dk/";

	public static void main(String a[]) {

		try {

			String url = retornarHTML();
			
			System.out.println("aaa");
			//a1.adicionarSite("oi", url);
			//ShowResults s = new ShowResults();
			//s.open(retorno);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static String cortarHTML(String html) throws Exception {
		String texto = html;
		int inicio = texto.indexOf("location.replace(") + 19;
		int fim = texto.lastIndexOf("\")");
		return site + texto.substring(inicio, fim);
		
	}
	public static String retornarHTML() throws Exception {
		con = new HTTPConnection(new URL("http://www.cbs.dtu.dk/services/NetMHC/"));

		NVPair[] post = { 
				new NVPair("configfile", "/usr/opt/www/pub/CBS/services/NetMHC-3.0/NetMHC.cf"), 
				new NVPair("SEQPASTE", "ASTPGHTIIYEAVCLHNDRTTIP"),
				new NVPair("peplen", "9"),
				new NVPair("alleles", "A0101")
			};
			
		rsp = con.Post("/cgi-bin/webface", post);
		
		String retorno = rsp.getText();
		String ret2 = cortarHTML(retorno);
		return ret2;
	}
}
